package com.imooc.sell.service.impl;

import com.imooc.sell.conf.ProjectUrlConfig;
import com.imooc.sell.dto.OrderDTO;
import com.imooc.sell.service.PushMessage;
import lombok.extern.slf4j.Slf4j;
import me.chanjar.weixin.common.exception.WxErrorException;
import me.chanjar.weixin.mp.api.WxMpService;
import me.chanjar.weixin.mp.bean.template.WxMpTemplateData;
import me.chanjar.weixin.mp.bean.template.WxMpTemplateMessage;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
@Slf4j
public class PushMessageImpl implements PushMessage {

    @Autowired
    private ProjectUrlConfig projectUrlConfig;

    @Autowired
    private WxMpService wxMpService;

    @Override
    public void orderStatus(OrderDTO orderDTO) {

        try {
            WxMpTemplateMessage templateMessage = WxMpTemplateMessage.builder().toUser("oTpb91XanzVr9JlM8dSLwgudu74w")
                    .templateId("80ihchGDm2qN_TJ9ldpRTlKmt_q1YriF0yxZtwctvF4")
                    .build();

            templateMessage.getData().add(new WxMpTemplateData("first","测试"));
            templateMessage.getData().add(new WxMpTemplateData("name","wuxubin"));
            templateMessage.getData().add(new WxMpTemplateData("project","sell"));

            wxMpService.getTemplateMsgService().sendTemplateMsg(templateMessage);
        } catch (WxErrorException e) {
            e.printStackTrace();
            log.error("模板消息发送失败");
        }

    }
}
